const mongoose=require('mongoose');
mongoose.set('strictQuery',true);

mongoose.connect('mongodb://127.0.0.1:27017/bookstore');
//4.设置成功回调 once一次 只执行一次
mongoose.connection.once('open',()=>{
// 5.创建文档的结构对象
// 设置集合 文档中的类型
    let BookSchema=new mongoose.Schema({
    name:String,
    author:String,
    price:Number
    });

//创建模型对象  对文档操作的封装对象
let BookModle=mongoose.model('book',BookSchema);

// BookModle.deleteOne({_id:'6568b3a0921d0511b4d0a527'},(err,data)=>{
    BookModle.deleteMany({author:'朝花夕1',name:'鲁迅'/*多条件*/},(err,data)=>{
    if(err)
    {
        console.log("删除失败");
        return;
    }
    console.log(data);

})

});
mongoose.connection.on('close',()=>{
    console.log('连接关闭');
});
mongoose.connection.on('err',()=>{
    console.log('出错了');
});